<!DOCTYPE html>
<html>
  



<head>
  <meta http-equiv="content-type" content="text/html; charset=utf-8">
  <meta content="width=device-width, initial-scale=1.0, maximum-scale=1.0, user-scalable=0" name="viewport">
  <!-- Global site tag (gtag.js) - Google Analytics -->


  <title>Android 12 行为变更 | 😄豐Dの个人博客</title>

  
    
<link rel="stylesheet" href="/js/aos/aos.css">

  

  <link rel="icon" type="image/x-icon, image/vnd.microsoft.icon" href="/favicon.ico">
  <link rel="stylesheet" href="https://at.alicdn.com/t/font_1911880_c1nvbyezg17.css">
  <link href="https://cdn.bootcdn.net/ajax/libs/font-awesome/4.7.0/css/font-awesome.min.css" rel="stylesheet">

  
    <script>
        var themeModelId = '';
        if (themeModelId) {
            localStorage.setItem('modelId', themeModelId);
        }
    </script>
    
    <script src="https://cdn.jsdelivr.net/gh/yuang01/live2d-widget@latest/autoload.js"></script>
    <script>
        var live2dOpen = eval('true') || false;
        if (!live2dOpen) {
            localStorage.setItem('waifu-display', 1609323474481);
        }
    </script>
  
  
<link rel="stylesheet" href="/css/animate.min.css">

  
<link rel="stylesheet" href="/css/style.css">

  
  
    
<link rel="stylesheet" href="/js/fancybox/jquery.fancybox.min.css">

  
  
  <style>
        @media (max-width: 992px) {
            #waifu {
                display: none;
            }
        }
    </style>
    <script src="//cdn.bootcss.com/pace/1.0.2/pace.min.js"></script>
    <link href="//cdn.bootcss.com/pace/1.0.2/themes/pink/pace-theme-flash.css" rel="stylesheet">
<meta name="generator" content="Hexo 5.3.0"></head>

  <script src="/js/jquery3.5.1.js"></script>
  <script src="/js/vue2.6.11.js"></script>
  <link href="/js/danmu/barrager.css" rel="stylesheet">
<script src="/js/danmu/jquery.barrager.js"></script>
  <body>
    <!-- 判断是否为黑夜模式 -->
    <script>
      let isDark = JSON.parse(localStorage.getItem('dark')) || JSON.parse('false');

      if (isDark) {
        $(document.body).addClass('darkModel');
      }
    </script>

    <header class="header bg-color" 
  style="position: fixed; 
  left: 0; top: 0; z-index: 10;width: 100%;"
>
  <div class="header-content">
    <div class="bars">
      <div id="appDrawer" class="sidebar-image">
  <i class="fa fa-bars" aria-hidden="true" @click="showDialogDrawer"></i>
  <transition name="fade">
    <div class="drawer-box_mask" v-cloak style="display: none;" v-show="visible" @click.self="cancelDialogDrawer">
    </div>
  </transition>
  <div class="drawer-box" :class="{'active': visible}">
    <div class="drawer-box-head bg-color">
      <img class="drawer-box-head_logo" src="/medias/logo.png" alt="logo">
      <h3 class="drawer-box-head_title">😄豐Dの个人博客</h3>
      <h5 class="drawer-box-head_desc">Lmfeng Blog</h5>
    </div>
    <div class="drawer-box-content">
      <ul class="drawer-box-content_menu">
        
          <li class="drawer-box-content_item">
            <a href="/" class="menu-item-link">
              
                <i class="fa fa-home" aria-hidden="true"></i>
              
              <span>首页</span>
            </a>
          </li>
        
          <li class="drawer-box-content_item">
            <a href="/archives" class="menu-item-link">
              
                <i class="fa fa-home" aria-hidden="true"></i>
              
              <span>归档</span>
            </a>
          </li>
        
          <li class="drawer-box-content_item">
            <a href="/tags" class="menu-item-link">
              
                <i class="fa fa-tags" aria-hidden="true"></i>
              
              <span>标签</span>
            </a>
          </li>
        
          <li class="drawer-box-content_item">
            <a href="/categories" class="menu-item-link">
              
                <i class="fa fa-bookmark" aria-hidden="true"></i>
              
              <span>分类</span>
            </a>
          </li>
        
          <li class="drawer-box-content_item">
            <a href="/about" class="menu-item-link">
              
                <i class="fa fa-user" aria-hidden="true"></i>
              
              <span>关于</span>
            </a>
          </li>
        
          <li class="drawer-box-content_item">
            <a target="_blank" rel="noopener" href="https://developer.android.google.cn/" class="menu-item-link">
              
                <i class="fa fa-link" aria-hidden="true"></i>
              
              <span>友情链接</span>
            </a>
          </li>
        
        <li class="drawer-box-content_item">
          <a target="_blank" rel="noopener" href="https://github.com/melvin11112015/">
            <i class="fa fa-github" aria-hidden="true"></i>
            <span>Github</span>
          </a>
        </li>
      </ul>
    </div>
  </div>
</div>

<script>
  var body = document.body || document.documentElement || window;
  var vm = new Vue({
    el: '#appDrawer',
    data: {
      visible: false,
      top: 0,
    },
    computed: {
    },
    mounted() {
    },
    methods: {
      showDialogDrawer() {
        this.visible = true;
        // 防止页面滚动，只能让弹框滚动
        this.top = $(document).scrollTop()
        body.style.cssText = 'width: 100%; height: 100%; position: fixed; top: -' + this.top  + 'px; left: 0; overflow: hidden;';
      },
      cancelDialogDrawer() {
        this.visible = false;
        body.removeAttribute('style');
        $(document).scrollTop(this.top)
      }
    },
    created() {}
  })
</script>
    </div>
    <div class="blog-title" id="author-avatar">
      <div class="avatar">
        <img src="/medias/logo.png" alt="logo">
      </div>
      <a href="/" class="logo">😄豐Dの个人博客</a>
    </div>
    <nav class="navbar">
      <ul class="menu">
        
          <li class="menu-item">
            <a href="/" class="menu-item-link">
              
                <i class="fa fa-home" aria-hidden="true"></i>
              
              <span>首页</span>
            </a>
          </li>
        
          <li class="menu-item">
            <a href="/archives" class="menu-item-link">
              
                <i class="fa fa-archive" aria-hidden="true"></i>
              
              <span>归档</span>
            </a>
          </li>
        
          <li class="menu-item">
            <a href="/tags" class="menu-item-link">
              
                <i class="fa fa-tags" aria-hidden="true"></i>
              
              <span>标签</span>
            </a>
          </li>
        
          <li class="menu-item">
            <a href="/categories" class="menu-item-link">
              
                <i class="fa fa-bookmark" aria-hidden="true"></i>
              
              <span>分类</span>
            </a>
          </li>
        
          <li class="menu-item">
            <a href="/about" class="menu-item-link">
              
                <i class="fa fa-user" aria-hidden="true"></i>
              
              <span>关于</span>
            </a>
          </li>
        
          <li class="menu-item">
            <a target="_blank" rel="noopener" href="https://developer.android.google.cn/" class="menu-item-link">
              
                <i class="fa fa-link" aria-hidden="true"></i>
              
              <span>友情链接</span>
            </a>
          </li>
        
      </ul>
      
        <div class="dark">
  <div class="dark-content">
    <i class="fa fa-moon-o" aria-hidden="true"></i>
    <!-- <span>关灯</span> -->
  </div>
  
</div>

<script>
  $(function() {
    let isDark = JSON.parse(localStorage.getItem('dark'))  || JSON.parse('false');
    if (isDark) {
      $(".dark-content").replaceWith(
          `
          <div class='dark-content'>
            <i class="fa fa-lightbulb-o" aria-hidden="true"></i>
          </div>
          `
        );
    }
    $('.dark').click(function() {
      if ($(document.body).is('.darkModel')) {
        $(document.body).removeClass('darkModel');
        localStorage.setItem('dark', false);
        $(".dark-content").replaceWith(
          `
          <div class='dark-content'>
            <i class="fa fa-moon-o" aria-hidden="true"></i>
          </div>
          `
        );
      } else {
        $(document.body).addClass('darkModel');
        localStorage.setItem('dark', true);
        $(".dark-content").replaceWith(
          `
          <div class='dark-content'>
            <i class="fa fa-lightbulb-o" aria-hidden="true"></i>
          </div>
          `
        );
      }
    })
  })
</script>
        
      
        <div id="appSearch">
  <div class="search"  @click="showDialog()"><i class="fa fa-search" aria-hidden="true"></i></div>
  <transition name="fade">
    <div class="message-box_wrapper" style="display: none;" v-cloak v-show="dialogVisible" @click.self="cancelDialogVisible()">
      <div class="message-box animated bounceInDown">
        <div class="close" style="overflow: hidden;">
          <i class="fa fa-close" aria-hidden="true" style="float:right;" @click.self="cancelDialogVisible()"></i>
        </div>
        <h2>
          <i class="fa fa-search" aria-hidden="true"></i>
          <span class="title">本地搜索</span>
          <!-- <i class="fa fa-close" style="float:right;" aria-hidden="true" @click.self="cancelDialogVisible()"></i> -->
        </h2>
        <form class="site-search-form">
          <input type="text"
            placeholder="请输入关键字"
            id="local-search-input" 
            @click="getSearchFile()"
            class="st-search-input"
            v-model="searchInput"
          />
        </form>
        <div class="result-wrapper">
          <div id="local-search-result" class="local-search-result-cls"></div>
        </div>
      </div>
    </div>
  </transition>
</div>
<script src="/js/local_search.js"></script>
<script>
  var body = document.body || document.documentElement || window;
  var vm = new Vue({
    el: '#appSearch',
    data: {
      dialogVisible: false,
      searchInput: '',
      top: 0,
    },
    computed: {
    },
    mounted() {
    },
    methods: {
      showDialog() {
        this.dialogVisible = true;
        // 防止页面滚动，只能让弹框滚动
        this.top = $(document).scrollTop()
        body.style.cssText = 'overflow: hidden;';
      },
      getSearchFile() {
        if (!this.searchInput) {
          getSearchFile("/search.xml");
        }
      },
      cancelDialogVisible() {
        this.dialogVisible = false;
        body.removeAttribute('style');
        $(document).scrollTop(this.top)
      },
    },
    created() {}
  })
</script>
<!-- 解决刷新页面闪烁问题，可以在元素上添加display: none, 或者用vue.extend方法，详情：https://blog.csdn.net/qq_31393401/article/details/81017912 -->
<!-- 下面是搜索基本写法 -->
<!-- <script type="text/javascript" id="local.search.active">
  var inputArea = document.querySelector("#local-search-input");
  inputArea.onclick   = function(){ getSearchFile(); this.onclick = null }
  inputArea.onkeydown = function(){ if(event.keyCode == 13) return false }
</script> -->

      

    </nav>
  </div>
  
  <a target="_blank" rel="noopener" href="https://github.com/melvin11112015/" class="github-corner color-primary" aria-label="View source on GitHub"><svg width="60" height="60" viewBox="0 0 250 250" style="fill:#fff; position: absolute; top: 0; border: 0; right: 0;" aria-hidden="true"><path d="M0,0 L115,115 L130,115 L142,142 L250,250 L250,0 Z"></path><path d="M128.3,109.0 C113.8,99.7 119.0,89.6 119.0,89.6 C122.0,82.7 120.5,78.6 120.5,78.6 C119.2,72.0 123.4,76.3 123.4,76.3 C127.3,80.9 125.5,87.3 125.5,87.3 C122.9,97.6 130.6,101.9 134.4,103.2" fill="currentColor" style="transform-origin: 130px 106px;" class="octo-arm"></path><path d="M115.0,115.0 C114.9,115.1 118.7,116.5 119.8,115.4 L133.7,101.6 C136.9,99.2 139.9,98.4 142.2,98.6 C133.8,88.0 127.5,74.4 143.8,58.0 C148.5,53.4 154.0,51.2 159.7,51.0 C160.3,49.4 163.2,43.6 171.4,40.1 C171.4,40.1 176.1,42.5 178.8,56.2 C183.1,58.6 187.2,61.8 190.9,65.4 C194.5,69.0 197.7,73.2 200.1,77.6 C213.8,80.2 216.3,84.9 216.3,84.9 C212.7,93.1 206.9,96.0 205.4,96.6 C205.1,102.4 203.0,107.8 198.3,112.5 C181.9,128.9 168.3,122.5 157.7,114.1 C157.9,116.9 156.7,120.9 152.7,124.9 L141.0,136.5 C139.8,137.7 141.6,141.9 141.8,141.8 Z" fill="currentColor" class="octo-body"></path></svg></a><style>.github-corner:hover .octo-arm{animation:octocat-wave 560ms ease-in-out}@keyframes octocat-wave{0%,100%{transform:rotate(0)}20%,60%{transform:rotate(-25deg)}40%,80%{transform:rotate(10deg)}}@media (max-width:500px){.github-corner:hover .octo-arm{animation:none}.github-corner .octo-arm{animation:octocat-wave 560ms ease-in-out}}</style>
  
    <div id="he-plugin-simple"></div>
    <script>
      WIDGET = {
        CONFIG: {
          "modules": "012",
          "background": 5,
          "tmpColor": "4A4A4A",
          "tmpSize": 16,
          "cityColor": "4A4A4A",
          "citySize": 16,
          "aqiSize": 16,
          "weatherIconSize": 24,
          "alertIconSize": 18,
          "padding": "10px 10px 10px 10px",
          "shadow": "1",
          "language": "auto",
          "borderRadius": 5,
          "fixed": "false",
          "vertical": "middle",
          "horizontal": "center",
          "key": "2784dd3fcb1e4f0f9a9b579bf69641f2"
        }
      }
    </script>
    <script src="https://widget.qweather.net/simple/static/js/he-simple-common.js?v=2.0"></script> 
    
</header>
    <main class="main" style="margin-top: 60px;">
      
 <!-- prismjs 代码高亮 -->
 

<div class="bg-dark-floor" style="position: fixed;left: 0;top: 0;width: 100%;height: 100%;z-index: -1;"></div>
<div id="appBgSwiper" style="position: fixed;left: 0;top: 0;width: 100%;height: 100%;z-index: -2;" :style="{'background-color': bgColor ? bgColor : 'transparent'}">
    <transition-group tag="ul" :name="names">
        <li v-for='(image,index) in img' :key='index' v-show="index === mark" class="bg-swiper-box">
            <img :src="image" class="bg-swiper-img">
        </li>
    </transition-group>
</div>
<script>
    var vm = new Vue({
        el: '#appBgSwiper',
        data: {
            names: '' || 'fade' || 'fade', // translate-fade fade
            mark: 0,
            img: [],
            bgColor: '',
            time: null
        },
        methods: {   //添加方法
            change(i, m) {
                if (i > m) {
                    // this.names = 'fade';
                } else if (i < m) {
                    // this.names = 'fade';
                } else {
                    return;
                }
                this.mark = i;
            },
            prev() {
                // this.names = 'fade';
                this.mark--;
                if (this.mark === -1) {
                    this.mark = 3;
                    return
                }
            },
            next() {
                // this.names = 'fade';
                this.mark++;
                if (this.mark === this.img.length) {
                    this.mark = 0;
                    return
                }
            },
            autoPlay() {
                // this.names = 'fade';
                this.mark++;
                if (this.mark === this.img.length) {
                    this.mark = 0;
                    return
                }
            },
            play() {
                let bgImgDelay = '' || '180000'
                let delay = parseInt(bgImgDelay) || 180000;
                this.time = setInterval(this.autoPlay, delay);
            },
            enter() {
                clearInterval(this.time);
            },
            leave() {
                this.play();
            }
        },
        created() {
            this.play()
        },
        beforeDestroy() {
            clearInterval(this.time);
        },
        mounted() {
            let prop = ''|| '';
            let isImg = prop.includes('.bmp') || prop.includes('.jpg') || prop.includes('.png') || prop.includes('.tif') || prop.includes('.gif') || prop.includes('.pcx') || prop.includes('.tga') || prop.includes('.exif') || prop.includes('.fpx') || prop.includes('.psd') || prop.includes('.cdr') || prop.includes('.pcd') || prop.includes('.dxf') || prop.includes('.ufo') || prop.includes('.eps') || prop.includes('.ai') || prop.includes('.raw') || prop.includes('.WMF') || prop.includes('.webp') || prop.includes('.jpeg')
            if (isImg) {
                let img = prop.split(',');
                let configRoot = '/'
                let arrImg = [];
                img.forEach(el => {
                    var Expression=/http(s)?:\/\/([\w-]+\.)+[\w-]+(\/[\w- .\/?%&=]*)?/;
			        var objExp = new RegExp(Expression);

                    if(objExp.test(el)) {
                        // http or https
                        arrImg.push(el);
                    } else {
                        // 非http or https开头
                        // 本地文件
                        let firstStr = el.charAt(0);
                        if (firstStr == '/') {
                            el = el.substr(1); // 删除第一个字符 '/',因为 configRoot最后一个字符为 /
                        }
                        el = configRoot + el;
                        arrImg.push(el);
                    }
                })
                this.img = arrImg;
            } else {
                this.bgColor = prop;
            }
        }
    })
</script>

<style>
    .bg-swiper-box {
        position: absolute;
        display: block;
        width: 100%;
        height: 100%;
    }
    .bg-swiper-img {
        object-fit: cover;
        width: 100%;
        height: 100%;
    }
</style>



<div class="post-detail-header lazyload" id="thumbnail_canvas" data-original="/img/android12-hero.svg" style="background-repeat: no-repeat; background-size: cover; 
  background-position: center center;position: relative;">
  <div class="post-detail-header-mask"></div>
  <canvas id="header_canvas"style="position:absolute;bottom:0"></canvas>
  
    <div class="title-box">
      
        <span class="title" id="post-detail-header-title"></span>
        <script src="https://cdn.jsdelivr.net/npm/typed.js@2.0.11"></script>
          <script>
            var typed = new Typed("#post-detail-header-title", {
              strings: ['Android 12 行为变更'],
              startDelay: 100,
              typeSpeed: 100,
              loop: false,
              backSpeed: 50,
              showCursor: false
            });
          </script>
        
    </div>
  
  
  
    <script src="/js/bubble/bubble.js"></script>
  
</div>


<div class="row justify-position">
  <div class="main-content">
    <article class="post post-detail">
      
      
      <div class="post-meta">
        <i class="fa fa-clock-o" aria-hidden="true"></i>
        <span class="post-time">2021-02-19</span>
      </div>
      
      <div class="post-tags-categories">
        
        <div class="tags">
          <i class="iconfont icontag"></i>
          
            <a href="/tags/Android-12/" class="">
              Android 12
            </a>
          
        </div>
        
        
        <div class="categories">
          <i class="iconfont iconbookmark1"></i>
          
            <a href="/categories/Android/" class="">
              Android
            </a>
          
        </div>
        
      </div>
      <div class="post-content">
        <h2 id="用户体验"><a href="#用户体验" class="headerlink" title="用户体验"></a>用户体验</h2><h3 id="沉浸式手势导航改进"><a href="#沉浸式手势导航改进" class="headerlink" title="沉浸式手势导航改进"></a>沉浸式手势导航改进</h3><p>Android 12简化了沉浸式模式，使手势导航更加轻松，并且与观看视频和读书等活动的其余部分更加一致。应用仍然可以<a href="/reference/android/view/WindowInsetsController#BEHAVIOR_SHOW_TRANSIENT_BARS_BY_SWIPE">防止</a> 全屏游戏体验中的<a href="/reference/android/view/WindowInsetsController#BEHAVIOR_SHOW_TRANSIENT_BARS_BY_SWIPE">意外手势</a>，因此用户在玩游戏时不会意外退出游戏；现在，所有其他全屏或身临其境的体验都允许用户一键浏览手机。</p>
<p>要做到这一点，对于非粘性身临其境的体验现有的行为（<a href="/reference/android/view/WindowInsetsController#BEHAVIOR_SHOW_BARS_BY_TOUCH"><code>BEHAVIOR_SHOW_BARS_BY_TOUCH</code></a>， <a href="/reference/android/view/WindowInsetsController#BEHAVIOR_SHOW_BARS_BY_SWIPE"><code>BEHAVIOR_SHOW_BARS_BY_SWIPE</code></a>）已被弃用Android中12开始，他们已被替换缺省行为（<a href="/reference/android/view/WindowInsetsController#BEHAVIOR_DEFAULT"><code>BEHAVIOR_DEFAULT</code></a>），允许比划着一个刷卡隐藏系统栏时。此标志根据模式显示不同的视觉和功能行为：</p>
<ul>
<li>  在三键模式下，视觉和功能行为与12之前的Android版本中的沉浸模式相同。</li>
<li>在手势导航模式下，行为如下：<ul>
<li>  在视觉上，它与Android 11及更低版本中的沉浸模式相同。</li>
<li>  从功能上讲，即使隐藏了栏，也允许使用手势。系统后部仅需要一次滑动即可调用，而无需使用Android 11的两次滑动。无需其他滑动即可拉下通知栏或开始回家。</li>
</ul>
</li>
</ul>
<p><a href="/reference/android/view/WindowInsetsController#BEHAVIOR_SHOW_TRANSIENT_BARS_BY_SWIPE"><code>BEHAVIOR_SHOW_TRANSIENT_BARS_BY_SWIPE</code></a>对于Android 12，粘性沉浸模式（）并未更改。请注意此功能具有以下向后兼容性：</p>
<ul>
<li>对于以Android 11和更低版本为目标的在Android 12上运行的应用：<ul>
<li>  <code>BEHAVIOR_SHOW_TRANSIENT_BARS_BY_SWIPE</code> 在功能和视觉上都表现相同。</li>
<li>  默认设置映射到<a href="/reference/android/view/WindowInsetsController#BEHAVIOR_SHOW_BARS_BY_SWIPE"><code>BEHAVIOR_SHOW_BARS_BY_SWIPE</code></a>。</li>
</ul>
</li>
<li>对于在Android 11（API级别30）及更低版本（针对Android 12）上运行的应用：<ul>
<li>  除了<a href="/reference/android/view/WindowInsetsController#BEHAVIOR_SHOW_BARS_BY_TOUCH"><code>BEHAVIOR_SHOW_BARS_BY_TOUCH</code></a> 映射到之外，预期具有相同的行为<a href="/reference/android/view/WindowInsetsController#BEHAVIOR_SHOW_BARS_BY_SWIPE"><code>BEHAVIOR_SHOW_BARS_BY_SWIPE</code></a>。</li>
<li>  确保将您的SDK级别更新为新的默认值（<a href="/reference/android/view/WindowInsetsController#BEHAVIOR_SHOW_BARS_BY_SWIPE"><code>BEHAVIOR_SHOW_BARS_BY_SWIPE</code></a>）。否则，<a href="/reference/android/view/WindowInsetsController#BEHAVIOR_SHOW_BARS_BY_TOUCH"><code>BEHAVIOR_SHOW_BARS_BY_TOUCH</code></a> 保留默认值。</li>
</ul>
</li>
</ul>
<h3 id="前台服务通知延迟"><a href="#前台服务通知延迟" class="headerlink" title="前台服务通知延迟"></a>前台服务通知延迟</h3><p>为了为Android 12上的短期运行的<a href="/guide/components/foreground-services">前台服务</a>提供简化的体验，系统可以将某些前台服务的前台服务通知显示延迟10秒。此更改使短期任务有机会在其通知出现之前完成。</p>
<p>如果前台服务至少具有以下特征之一，则系统在服务启动后立即显示关联的通知：</p>
<ul>
<li>  该服务与包含<a href="/training/notify-user/build-notification#Actions">操作按钮</a>的通知关联。</li>
<li>  该服务拥有 <a href="/guide/topics/manifest/service-element#foregroundservicetype"><code>foregroundServiceType</code></a> 的<code>connectedDevice</code>，<code>mediaPlayback</code>，<code>mediaProjection</code>，或<code>phoneCall</code>。</li>
<li>该服务提供了在通知的<a href="/reference/android/app/Notification#category">category属性中</a>定义的与电话，导航或媒体播放有关的用例。  <strong>注意：</strong>这些用例可能会在将来的Android 12 Developer Preview版本中进行更改。</li>
<li>该服务已通过<a href="/reference/android/app/Notification.Builder#setShowForegroundImmediately(boolean)"><code>setShowForegroundImmediately()</code></a> 在设置通知时进行调用来退出行为更改 。</li>
</ul>
<h2 id="隐私"><a href="#隐私" class="headerlink" title="隐私"></a>隐私</h2><h3 id="Netlink-MAC地址限制"><a href="#Netlink-MAC地址限制" class="headerlink" title="Netlink MAC地址限制"></a>Netlink MAC地址限制</h3><p>Android 12进一步限制了所有非系统应用程序对设备MAC地址（不可重置的标识符）的访问，无论目标API级别如何。</p>
<p>相关API会返回空值或占位符值，具体取决于应用程序的目标SDK版本：</p>
<ul>
<li>  如果您的应用针对Android 12，则API返回null。</li>
<li>  如果您的应用定位到Android 11或更低版本，则API返回硬编码的占位符值： <code>02:00:00:00:00:00</code></li>
</ul>
<p>开发人员应该使用<a href="/reference/android/net/ConnectivityManager"><code>ConnectivityManager</code></a> ，而不是低级别的API，如<a href="/reference/java/net/NetworkInterface"><code>NetworkInterface</code></a>， <code>getifaddrs()</code>或网络链路插槽。当开发人员调用<code>NetworkInterface.getHardwareAddress()</code> 其代码时，logcat输出显示： <code>CompatibilityChangeReporter: Compat change id reported: 170188668;</code></p>
<p>开发人员可以使用调用的兼容性标志<code>[RETURN_NULL_HARDWARE_ADDRESS](/reference/compat-framework-changes?db=dac-team#return_null_hardware_address)</code> 来切换<code>NetworkInterface.getHardwareAddress()</code> 启用或<code>02:00:00:00:00:00</code>禁用时返回null的行为。</p>
<h2 id="安全"><a href="#安全" class="headerlink" title="安全"></a>安全</h2><h3 id="不信任的触摸事件被阻止"><a href="#不信任的触摸事件被阻止" class="headerlink" title="不信任的触摸事件被阻止"></a>不信任的触摸事件被阻止</h3><p>为了维护系统安全性和良好的用户体验，Android 12会阻止应用程序在覆盖层以不安全的方式遮盖应用程序时使用<a href="/training/gestures">触摸事件</a>。换句话说，系统会阻止通过某些窗口的触摸，但<a href="#untrusted-touch-events-exceptions">有一些例外</a>。</p>
<h4 id="受影响的应用"><a href="#受影响的应用" class="headerlink" title="受影响的应用"></a>受影响的应用</h4><p>此更改会影响选择让触摸通过其窗口（例如通过使用 <a href="/reference/android/view/WindowManager.LayoutParams#FLAG_NOT_TOUCHABLE"><code>FLAG_NOT_TOUCHABLE</code></a> 标志）的应用。几个示例包括但不限于以下示例：</p>
<ul>
<li>  需要<a href="/reference/android/Manifest.permission#SYSTEM_ALERT_WINDOW"><code>SYSTEM_ALERT_WINDOW</code></a> 权限的叠加层 ，例如使用<a href="/reference/android/view/WindowManager.LayoutParams#TYPE_APPLICATION_OVERLAY"><code>TYPE_APPLICATION_OVERLAY</code></a>，使用<code>FLAG_NOT_TOUCHABLE</code>标志的窗口 。</li>
<li>  使用该<code>FLAG_NOT_TOUCHABLE</code>标志的活动窗口。</li>
<li>  <a href="/guide/topics/ui/notifiers/toasts">敬酒消息</a>。</li>
</ul>
<h4 id="例外情况"><a href="#例外情况" class="headerlink" title="例外情况"></a>例外情况</h4><p>在以下情况下，允许“通过”触摸：</p>
<ul>
<li>  <strong>您的应用内的互动。</strong>您的应用会显示叠加层，并且叠加层仅在用户与您的应用进行交互时才会显示。</li>
<li><strong>受信任的窗口。</strong>这些窗口包括（但不限于）以下内容：<ul>
<li><p>  <a href="/reference/android/view/WindowManager.LayoutParams#TYPE_ACCESSIBILITY_OVERLAY">辅助功能窗口</a></p>
</li>
<li><p>  <a href="/reference/android/view/WindowManager.LayoutParams#TYPE_INPUT_METHOD">输入法编辑器（IME）窗口</a></p>
</li>
<li><p><a href="/reference/android/view/WindowManager.LayoutParams#FLAG_NOT_TOUCHABLE">助手窗口</a></p>
</li>
<li><p>*注意：<strong>Windows类型 **不受</strong>信任。<a href="/reference/android/view/WindowManager.LayoutParams#TYPE_APPLICATION_OVERLAY"><code>TYPE_APPLICATION_OVERLAY</code></a></p>
</li>
</ul>
</li>
<li><strong>隐形窗户。</strong>窗口的根视图为 <a href="/reference/android/view/View#GONE"><code>GONE</code></a>或 <a href="/reference/android/view/View#INVISIBLE"><code>INVISIBLE</code></a>。</li>
<li><strong>完全透明的窗口。</strong>该<a href="/reference/android/view/WindowManager.LayoutParams#alpha"><code>alpha</code></a>窗口的 属性为0.0。</li>
<li><strong>足够透明的系统警报窗口。</strong>当组合的不透明度小于或等于系统对触摸的最大遮盖不透明度时，系统认为一组系统警报窗口是足够透明的。在Developer Preview 1中，最大不透明度为0.8，但是此值稍后可能在Developer Preview中更改。</li>
</ul>
<h4 id="检测何时阻止了不受信任的触摸"><a href="#检测何时阻止了不受信任的触摸" class="headerlink" title="检测何时阻止了不受信任的触摸"></a>检测何时阻止了不受信任的触摸</h4><p>如果触摸动作被系统阻止， <a href="/studio/command-line/logcat">Logcat会</a>记录以下消息：</p>
<pre><code>Untrusted touch due to occlusion by PACKAGE_NAME
</code></pre>
<h4 id="测试变更"><a href="#测试变更" class="headerlink" title="测试变更"></a>测试变更</h4><p>默认情况下，在运行Android 12 Developer Preview 1的设备上，不信任的触摸被阻止。要允许不信任的触摸，请在终端窗口中运行以下<a href="/studio/command-line/adb">ADB命令</a>：</p>
<p>＃特定的应用程序<br>adb shell可以禁用BLOCK_UNTRUSTED_TOUCHES com 。例子。应用程序  </p>
<p>＃所有应用程序＃如果在触摸被阻止时仍希望看到Logcat消息警告，请使用1而不是0。adb shell设置将global block_untrusted_touches 0  </p>
<p>要将行为恢复为默认行为（阻止了不信任的触摸），请运行以下命令：</p>
<p>＃一个特定的应用程序<br>adb shell兼容重置BLOCK_UNTRUSTED_TOUCHES com 。例子。应用程序  </p>
<p>＃所有应用程序<br>adb shell设置都放入全局block_untrusted_touches 2  </p>
<h3 id="应用无法关闭系统"><a href="#应用无法关闭系统" class="headerlink" title="应用无法关闭系统"></a>应用无法关闭系统</h3><p>为了在与应用程序和系统进行交互时改善用户控制，从 <a href="/reference/android/content/Intent#ACTION_CLOSE_SYSTEM_DIALOGS"><code>ACTION_CLOSE_SYSTEM_DIALOGS</code></a> Android 12开始不推荐使用intent操作。除<a href="#close-system-dialogs-exceptions">少数特殊情况外</a>，当您的应用程序尝试<a href="/guide/components/intents-filters">调用</a>包含此操作<a href="/guide/components/intents-filters">的intent时</a>，系统会执行以下操作之一在您应用的目标SDK版本上：</p>
<ul>
<li>  如果您的应用程序以Android 12为目标，<a href="/reference/java/lang/SecurityException"><code>SecurityException</code></a>则会出现a 。</li>
<li>如果您的应用定位到Android 11（API级别30）或更低版本，则该意图不会执行，并且<a href="/studio/command-line/logcat">Logcat中会</a>显示以下消息 ：  E ActivityTaskManager权限被拒绝：\<br>  从\广播的android.intent.action.CLOSE_SYSTEM_DIALOGS<br>  com.package.name需要android.permission.BROADCAST_CLOSE_SYSTEM_DIALOGS，\<br>  放下广播。</li>
</ul>
<h4 id="例外情况-1"><a href="#例外情况-1" class="headerlink" title="例外情况"></a>例外情况</h4><p>在以下情况下，应用仍可以在Android 12上关闭系统对话框：</p>
<ul>
<li>  您的应用正在运行<a href="/training/testing/unit-testing/instrumented-unit-tests">测试</a>。</li>
<li>您的应用定位到Android 11或更低版本，并且在<a target="_blank" rel="noopener" href="https://material.io/design/platform-guidance/android-notifications#behavior">通知抽屉的</a>顶部显示一个窗口。  <strong>注意：</strong>如果您的应用定位到Android 12，则<code>ACTION_CLOSE_SYSTEM_DIALOGS</code>在这种情况下无需使用 。这是因为，如果您的应用程序<a href="/reference/android/content/Context#startActivity(android.content.Intent)"><code>startActivity()</code></a> 在通知抽屉顶部有一个窗口的同时调用 ，则系统会自动关闭通知抽屉。</li>
<li>您的应用定位到Android 11或更低版本。此外，用户可能已经使用通知的<a href="/training/notify-user/build-notification#Actions">操作按钮</a>与通知进行了交互，并且您的应用正在响应该用户操作来处理<a href="/guide/components/services">服务</a>或<a href="/guide/components/broadcasts">广播接收器</a>。</li>
</ul>
<h2 id="非SDK接口限制"><a href="#非SDK接口限制" class="headerlink" title="非SDK接口限制"></a>非SDK接口限制</h2><p>Android 12包括基于与Android开发人员的协作以及最新的内部测试而更新的受限非SDK接口列表。只要有可能，在限制非SDK接口之前，请确保可以使用公共替代方案。</p>
<p>如果您的应用程序未针对Android 12，则其中的某些更改可能不会立即影响您。但是，尽管您目前可以使用某些非SDK接口（<a href="/guide/app-compatibility/restrictions-non-sdk-interfaces#list-names">取决于应用程序的目标API级别</a>），但是使用任何非SDK方法或字段始终会带来破坏应用程序的高风险。</p>
<p>如果不确定您的应用程序是否使用非SDK接口，则可以<a href="/guide/app-compatibility/restrictions-non-sdk-interfaces#test-for-non-sdk">测试您的应用程序</a> 以找出答案。如果您的应用依赖于非SDK界面，则应开始计划向SDK替代产品的迁移。不过，我们了解到某些应用程序具有使用非SDK接口的有效用例。如果您找不到在应用程序中为功能使用非SDK接口的替代方法，则应<a href="/guide/app-compatibility/restrictions-non-sdk-interfaces#feature-request">请求一个新的Public API</a>。</p>
<p>要了解有关此版本Android中的更改的更多信息，请参阅<a href="/about/versions/12/non-sdk-12">Android 12中非SDK接口限制的更新</a>。要大致了解有关非SDK接口的更多信息，请参阅<a href="/guide/app-compatibility/restrictions-non-sdk-interfaces">非SDK接口限制</a>。</p>

      </div>
      
    </article>
    <!-- 上一篇文章和下一篇文章 -->
    
      
<div class="post-nav">





  
  <div class="post-nav-next post-nav-item">
    <div class="post-nav-img lazyload" data-original="/img/xian.jpg" style="background-size: cover; 
      background-position: center center;">
    </div>
    <a href="/2020/10/03/2104/" class="post-nav-link">
      <div class="title">
        下一篇: <i class="fa fa-angle-right"></i>
        <div>长安秋望</div>
      </div>
      <!-- <div class="content">
        
楼倚霜树外，镜天无一毫。
南山与秋色，气势两相高。

      </div> -->
    </a>
  </div>

</div>

    
    

    <!-- 打赏 -->
    

    <!-- 分享 -->
    
    
    <!-- 评论 -->
      
        <div id="myComment">
          
        </div>
      
  </div>

  
    <div class="toc-aside">
      <div class="toc-main">
        <div class="toc-aside-title">
          <i class="fa fa-list-ul" aria-hidden="true"></i><span>本文目录</span>
          <div class="toc-open-close">本文目录</div>
        </div>
        <div class="toc-content">
          <link href="/js/tocbot/tocbot.css" rel="stylesheet">
<script src="/js/tocbot/tocbot.min.js"></script>
<div class="toc"></div>

<script>
  if ($('.toc').length > 0) {
    var headerEl = 'h2, h3, h4',  //headers 
      content = '.post-detail',//文章容器
      idArr = {};  //标题数组以确定是否增加索引id
      //add #id

    $(content).children(headerEl).each(function () {
      //去除空格以及多余标点
      var headerId = $(this).text().replace(/[\s|\~|`|\!|\@|\#|\$|\%|\^|\&|\*|\(|\)|\_|\+|\=|\||\|\[|\]|\{|\}|\;|\:|\"|\'|\,|\<|\.|\>|\/|\?|\：|\，|\。]/g, '');

      headerId = headerId.toLowerCase();
      if (idArr[headerId]) {
        //id已经存在
        $(this).attr('id', headerId + '-' + idArr[headerId]);
        idArr[headerId]++;
      }
      else {
        //id未存在
        idArr[headerId] = 1;
        $(this).attr('id', headerId);
      }
    });

    tocbot.init({
      // Where to render the table of contents.
      tocSelector: '.toc',
      // Where to grab the headings to build the table of contents.
      contentSelector: content,
      // Which headings to grab inside of the contentSelector element.
      headingSelector: headerEl,
      scrollSmooth: true,
      scrollSmoothOffset: -80,
      headingsOffset: 130,
      positionFixedSelector: '.toc-main',
      positionFixedClass: 'is-position-fixed',
      fixedSidebarOffset: 'auto',
    });
  }

</script>

<style>
.is-position-fixed {
  position:fixed !important;
  top: 64px;
}
.toc-main ul {
  counter-reset: show-list;
}
.toc-main ul li::before {
  content: counter(item)".";
  display: block;
  position: absolute;
  left: 12px;
  top:0;
}
.toc > .toc-list {
  padding-left: 35px;
}
.toc>.toc-list li {
  list-style: decimal;
}
.toc-list {
  padding-left: 25px;
}
</style>
        </div>
      </div>
    </div>

    

    <script>
      let openOrCloseBtn = $('.toc-aside .toc-aside-title .toc-open-close');
      let open = eval('' || 'true');
      openOrCloseBtn.click(function() {
        if (open === true) {
          $(".toc-aside").css({'width': 0, 'padding': 0});
          $(".toc-content").css({'width': 0});
          $(".toc-aside-title span, .toc-aside-title i").css({'display': 'none'});
          $(".main-content").css({'width': '75%', 'margin': '10px auto'});
          open = false;
        } else {
          $(".toc-aside").css({'width': '300px', 'padding': '0 10px'});
          $(".toc-content").css({'width': '300px'});
          $(".toc-aside-title span, .toc-aside-title i").css({'display': 'inline-block'});
          $(".main-content").css({'width': '65%', 'margin-right': '10px', 'margin-left': 'calc(35% - 350px)'});
          open = true;
        }
      });
    </script>
  
</div>


    </main>
    <div class="footer bg-color">
  <div class="footer-main">
<!--    <div class="link">
      <a target="_blank" rel="noopener" href="https://github.com/yuang01/hexo-theme-bamboo">
        <i class="fa fa-github" aria-hidden="true"></i>
      </a>
      <a href="mailto:1730241541@qq.com">
        <i class="fa fa-envelope-o" aria-hidden="true"></i>
      </a>
      <a href="tencent://AddContact/?fromId=50&fromSubId=1&subcmd=all&uin=1730241541">
        <i class="fa fa-qq" aria-hidden="true"></i>
      </a>
      <a href="/atom.xml" target="_blank">
        <i class="fa fa-rss" aria-hidden="true"></i>
      </a>
    </div>
-->
    <div class="footer-copyright">
      Copyright © 2015 - 2021 <a href="/about">Melvin</a> | Powered by <a target="_blank" rel="noopener" href="https://hexo.io/zh-cn/docs/">Hexo</a> | Theme <a target="_blank" rel="noopener" href="https://github.com/yuang01/theme">Bamboo</a> 
    </div>
    
  </div>
</div>


    
      <div class="goTop top-btn-color border-color">
  <i class="fa fa-arrow-up" aria-hidden="true"></i>
</div>
<script src="/js/goTop.js"></script>
    

    

    <!-- 图片放大 -->
    
      <script src="/js/fancybox/jquery.fancybox.min.js"></script>
    

    <script src="/js/wrapImage.js"></script>
    
    <!-- 爱心点击 -->
    
      
        <canvas class="fireworks" style="position: fixed;left: 0;top: 0;z-index: 999; pointer-events: none;" ></canvas>
        <script src="//cdn.bootcss.com/animejs/2.2.0/anime.min.js"></script>
        <script src="/js/cursor/explosion.min.js"></script>
      
    

    <!-- Baidu Analytics -->

    <!-- Baidu Push -->

<script>
    (function () {
        var bp = document.createElement('script');
        var curProtocol = window.location.protocol.split(':')[0];
        if (curProtocol === 'https') {
            bp.src = 'https://zz.bdstatic.com/linksubmit/push.js';
        } else {
            bp.src = 'http://push.zhanzhang.baidu.com/push.js';
        }
        var s = document.getElementsByTagName("script")[0];
        s.parentNode.insertBefore(bp, s);
    })();
</script>

    
    <script type="text/javascript" size="100" alpha='0.4' zIndex="-1" src="/js/ribbon.min.js"></script>
    
      <script src="/js/aos/aos.js"></script>
      <script>
        // https://github.com/michalsnik/aos
        const themeOffset = parseInt('120') || 120;
        const themeDelay = parseInt('0')|| 0;
        const themeDuration = parseInt('400') || 400;
        const themeEasing = 'ease' || 'ease';
        const themeOnce = eval('true') || false;
        const themeMirror = eval('false') || false;
        const themeAnchorPlacement = 'top-bottom' || 'top-bottom';
        AOS.init({
          // Global settings:
          disable: false, // accepts following values: 'phone', 'tablet', 'mobile', boolean, expression or function
          startEvent: 'DOMContentLoaded', // name of the event dispatched on the document, that AOS should initialize on
          initClassName: 'aos-init', // class applied after initialization
          animatedClassName: 'aos-animate', // class applied on animation
          useClassNames: false, // if true, will add content of `data-aos` as classes on scroll
          disableMutationObserver: false, // disables automatic mutations' detections (advanced)
          debounceDelay: 50, // the delay on debounce used while resizing window (advanced)
          throttleDelay: 99, // the delay on throttle used while scrolling the page (advanced)

          // Settings that can be overridden on per-element basis, by `data-aos-*` attributes:
          offset: themeOffset, // offset (in px) from the original trigger point
          delay: themeDelay, // values from 0 to 3000, with step 50ms
          duration: themeDuration, // values from 0 to 3000, with step 50ms
          easing: themeEasing, // default easing for AOS animations
          once: themeOnce, // whether animation should happen only once - while scrolling down
          mirror: themeMirror, // whether elements should animate out while scrolling past them
          anchorPlacement: themeAnchorPlacement, // defines which position of the element regarding to window should trigger the animation

        });
      </script>
    

    
      <link rel="stylesheet" href="https://cdn.jsdelivr.net/npm/v-plugs-ayu/lib/ayu.css">
<script src="https://cdn.jsdelivr.net/npm/v-plugs-ayu/lib/ayu.umd.min.js"></script>
<div id="appCopy">
</div>
<script>
  var vm = new Vue({
    el: '#appCopy',
    data: {
    },
    computed: {
    },
    mounted() {
      const that = this;
      //  监听 ctrl + c事件  
      $(document).unbind('keypress').bind('keypress', function (e) {
        if (e.ctrlKey && e.keyCode == 67) {
          doSomething();
          // 返回false, 防止重复触发copy事件  
          return false;
        }
      })

      // 鼠标右键的复制事件  
      $(document).unbind('copy').bind('copy', function (e) {
        doSomething();
        // console.log('右键复制 监听成功');
      });

      function doSomething() {
        that.$notify({
          title: "成功",
          content: "代码已复制，请遵守相关授权协议。",
          type: 'success'
        })
        // console.log('ctrl + c 监听成功');  
      }
    },
    methods: {
    },
    created() { }
  })
</script>
    

    <!-- 输入框打字特效 -->
    
      <script src="/js/activate-power-mode.js"></script>
      <script>
          POWERMODE.colorful = true;  // 打开随机颜色特效
          POWERMODE.shake = false;    // 关闭输入框抖动
          document.body.addEventListener('input', POWERMODE);//监听打字事件
      </script>
    

    <!-- markdown代码一键复制功能 -->
    <script src="/js/clipboard/clipboard.min.js"></script>
    <script>
      !function (e, t, a) {
        var copy = '复制';
        /* code */
        var initCopyCode = function(){
          var copyHtml = '';
          copyHtml += '<button class="btn-copy" data-clipboard-snippet="" style="position:absolute;top:0;right:0;z-index:1;">';
          copyHtml += '<i class="fa fa-copy"></i><span>' + copy + '</span>';
          copyHtml += '</button>';
          $(".post-detail pre").not('.gutter pre').wrap("<div class='codeBox' style='position:relative;width:100%;'></div>")
          $(".post-detail pre").not('.gutter pre').before(copyHtml);
          new ClipboardJS('.btn-copy', {
              target: function(trigger) {
                  return trigger.nextElementSibling;
              }
          });
        }
        initCopyCode();
      }(window, document);
    </script>

    <script src="/js/lazyload/lazyload@1.9.1.js"></script>
    <script>
      $(function() {
        $("div.lazyload, img.lazyload, a.lazyload").lazyload(
            {
                effect: "fadeIn",
                placeholder: "https://img10.360buyimg.com/ddimg/jfs/t1/159345/8/2271/222193/5ff7b36fEe49f5663/a95287c20385127f.gif"    //图片未加载出来时显示的占位图
            }
        );
    });
    </script>
    
    <script src="/js/app.js"></script>
  </body>
</html>